<?php

extract(extractGet(), EXTR_PREFIX_ALL, 'u');

// If we pass email parameter, which is unique
if(!$getResultAsArray && isset($u_email)){
    echo $u_email;
     $user = R::findOne('user',' email = ? ',array($u_email));
     
     if(is_null($user)){
         jsonErrorDie("User with provided email does not exist.");
     }
     else{
         
         $user->possibleRoles = getPossibleUserRoles($user->id);
         jsonSuccessDie('users', array(json_decode($user)));
     }
}
else{
    $users = R::getAll( "SELECT * FROM user");
    // Changing user inplace
    foreach($users as &$user){
        $user["possible_roles"] = getPossibleUserRoles($user["id"]);        
    }

    if(!$getResultAsArray){
        jsonSuccessDie('users', $users);
    }
    
}
